package com.whfc.ms.api.fuum.service.impl;

import com.whfc.common.exception.BizException;
import com.whfc.common.result.ResultEnum;
import com.whfc.fuum.entity.AppMeetingMinutes;
import com.whfc.fuum.service.AppMeetingMinutesService;
import com.whfc.ms.api.fuum.service.MsMeetingMinutesService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会议纪要管理服务实现类
 *
 * @author dzg
 * @since 2025-11-21
 */
@Slf4j
@Service
public class MsMeetingMinutesServiceImpl implements MsMeetingMinutesService {

    @DubboReference(interfaceClass = AppMeetingMinutesService.class, version = "1.0.0")
    private AppMeetingMinutesService appMeetingMinutesService;

    @Override
    public AppMeetingMinutes getById(Integer id) {
        AppMeetingMinutes appMeetingMinutes = appMeetingMinutesService.getById(id);
        if (appMeetingMinutes == null) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "会议纪要不存在");
        }
        return appMeetingMinutes;
    }

    @Override
    public List<AppMeetingMinutes> list(Integer deptId, String name) {
        return appMeetingMinutesService.list(deptId, name);
    }

    @Override
    public boolean save(AppMeetingMinutes meetingMinutes) {
        boolean result = appMeetingMinutesService.save(meetingMinutes);
        if (!result)
            throw new BizException(ResultEnum.FAILURE.getCode(), "新增失败");
        return result;
    }

    @Override
    public boolean update(AppMeetingMinutes meetingMinutes) {
        AppMeetingMinutes existingMinutes = appMeetingMinutesService.getById(meetingMinutes.getId());
        if (existingMinutes == null) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "会议纪要不存在");
        }
        boolean result = appMeetingMinutesService.update(meetingMinutes);
        if (!result)
            throw new BizException(ResultEnum.FAILURE.getCode(), "更新失败");
        return result;
    }

    @Override
    public boolean delete(Integer id) {
        boolean result = appMeetingMinutesService.delete(id);
        if (!result)
            throw new BizException(ResultEnum.FAILURE.getCode(), "删除失败");
        return result;
    }

    @Override
    public boolean deleteBatch(List<Integer> ids) {
        boolean result = appMeetingMinutesService.deleteBatch(ids);
        if (!result)
            throw new BizException(ResultEnum.FAILURE.getCode(), "批量删除失败");
        return result;
    }
}